﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Happy.PessimisticLock.Internal
{
    internal class LockItem
    {
        private LockItem() { }

        public string Entity { get; private set; }

        public string Key { get; private set; }

        public string Owner { get; private set; }

        public IExpirationPolicy ExpirationPolicy { get; private set; }

        public string Identifier
        {
            get
            {
                return CreateIdentifier(this.Entity, this.Key);
            }
        }

        public static LockItem Crete(string entity, string key, string owner, IExpirationPolicy expirationPolicy)
        {
            return new LockItem
            {
                Entity = entity,
                Key = key,
                Owner = owner,
                ExpirationPolicy = expirationPolicy
            };
        }

        public static string CreateIdentifier(string entity, string key)
        {
            return entity + "-" + key;
        }
    }
}
